﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media.Imaging;
using Windows.Phone.Media.Capture;

namespace TakePhotoTogether.View
{
    public partial class NewMenu : UserControl
    {
        private MainPage m_mainPage;

        public NewMenu()
        {
            InitializeComponent();
        }

        internal void SetParent(MainPage mainPage)
        {
            m_mainPage = mainPage;
        }

        private void StackPanel_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            m_mainPage.NewMenu_Tap(sender, e);
        }

        private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            Utils.Log.StartLog("Image_Tap");

            if (m_mainPage.frontCameraOn)
            {
                m_mainPage.frontCameraButton_Click(sender, e);
                m_mainPage.NewMenu_Tap(sender, e);
                imgFlash.Source = new BitmapImage(new Uri("/Toolkit.Content/appbar.flash.off.rest.png", UriKind.Relative));
                if (m_mainPage.sensor == CameraSensorLocation.Back)
                {
                    imgFrontCamera.Source = new BitmapImage(new Uri("/Toolkit.Content/appbar.frontfacingcamera.dark.rest.png", UriKind.Relative));
                }
                else
                {
                    imgFrontCamera.Source = new BitmapImage(new Uri("/Toolkit.Content/appbar.frontfacingcamera.dark.down.png", UriKind.Relative));
                }
            }
            Utils.Log.EndLog("Image_Tap2");
        }

        private void Image_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            Utils.Log.StartLog("Image_Tap_1");
            if (m_mainPage.sensor == CameraSensorLocation.Back)
            {
                m_mainPage.flashButton_Click(sender, e);
                m_mainPage.NewMenu_Tap(sender, e);
                if (m_mainPage.FlashOn)
                {
                    imgFlash.Source = new BitmapImage(new Uri("/Toolkit.Content/appbar.flash.on.rest.png", UriKind.Relative));
                }
                if (m_mainPage.FlashOff)
                {
                    imgFlash.Source = new BitmapImage(new Uri("/Toolkit.Content/appbar.flash.off.rest.png", UriKind.Relative));
                }
                if (m_mainPage.FlashAuto)
                {

                    imgFlash.Source = new BitmapImage(new Uri("/Toolkit.Content/appbar.flash.auto.rest.png", UriKind.Relative));
                }
            }
            Utils.Log.StartLog("Image_Tap_1b");
        }

        private void imgFrontCamera_Loaded(object sender, RoutedEventArgs e)
        {
            imgFrontCamera.Source = new BitmapImage(new Uri("/Toolkit.Content/appbar.frontfacingcamera.dark.rest.png", UriKind.Relative));
        }

        private void imgFlash_Loaded(object sender, RoutedEventArgs e)
        {
            imgFlash.Source = new BitmapImage(new Uri("/Toolkit.Content/appbar.flash.on.rest.png", UriKind.Relative));
        }
    }
}
